package view;

import java.awt.Rectangle;

import model.ImageLoader;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

import controller.Game;

public abstract class Menuitem extends Spielelement{
	
	private String imagepath1;
	private String imagepath2;
	private Texture[] frame;
	private boolean isActive=false;
	private boolean isVisible = true;

	public Menuitem(int x, int y, String imagepath1, String imagepath2) {
		int sidelength = Game.FIELDSIZE;		
		this.position = new Rectangle(x, y, sidelength, sidelength);
		frame = new Texture[2];
		this.imagepath1 = imagepath1;
		this.imagepath2 = imagepath2;
	}
	
	/** Lade Bilder */
	@Override
	public void loadImage(ImageLoader loader){
		super.loadImage(loader);
		frame[0] = loadImageIntoQuad(imagepath1);
		frame[1] = loadImageIntoQuad(imagepath2);
	}
	
	@Override
	public void renderQuad(int dX, int dY) {
		if(isVisible){
			int x = position.x;
			int y = position.y;
			
			if(!isActive){
				frame[0].bind();
			}else{
				frame[1].bind();
			}
			
			/** Nullpunkt ist oben links!! */
			GL11.glBegin(GL11.GL_QUADS);
				/** Eckpunkt rechts unten */
				GL11.glTexCoord2f(1,1);
				GL11.glVertex2f(x + position.width, y);
				/** Eckpunkt unten links */
				GL11.glTexCoord2f(0,1);
				GL11.glVertex2f(x, y);
				/** Eckpunkt oben links */
				GL11.glTexCoord2f(0,0);
				GL11.glVertex2f(x, y + position.height);
				/** Eckpunkt oben rechts */
				GL11.glTexCoord2f(1,0);
				GL11.glVertex2f(x + position.width, y + position.height);
			GL11.glEnd();
		}
	}
	
	protected abstract void handleEnter(World world);

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	public boolean isVisible() {
		return isVisible;
	}

	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}

}
